home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / OldPatch / MPPatch.oldc < prev    next >
Text File  |  1997-12-01  |  37KB  |  1,265 lines

  1. #include "MP.h"
  2. //#include "/modepro.h"
  3. #include <graphics/videocontrol.h>
  4. #include <graphics/displayinfo.h>
  5. #include "patchdata.h"
  6.  
  7. //#define DEBUG
  8. #include <debug.h>
  9.  
  10. void WaitForReply(struct Message *Msg);
  11.  
  12. ULONG Colors[]={1<<16|0,~0,0,0,0};
  13.  
  14. //#define ADD_DEBUG_CODE
  15.  
  16.  
  17.  
  18. #define HAM_EHB_DP_KEY (HAM_KEY | 0x400 | EXTRAHALFBRITE_KEY)
  19. //                                DualPF
  20. //BOOL MPSem->Debug=FALSE;
  21.  
  22.  
  23.  
  24. /* kprintf
  25.  
  26. #ifdef ADD_DEBUG_CODE
  27.       if(MPSem->Debug)
  28.       {
  29.       }
  30. #endif
  31.  
  32. */
  33.  
  34. #define AllocOpenNode(on)  (on ? on: AllocMem(sizeof(struct OpenNode),MEMF_CLEAR|MEMF_PUBLIC))
  35.   
  36. void CatchDNode(ULONG Dest, UBYTE *Name, struct DefaultNode *SrcNode);
  37.  
  38. extern LONG InPatch;
  39. extern UBYTE   ModePro[];
  40. extern ULONG CenterAll;
  41. extern CxObj  *Broker;
  42. extern struct MsgPort *BrokerPort;
  43. extern BOOL   V39;
  44. extern BYTE   PublicSignal;
  45. extern struct MPSem *MPSem;
  46. extern struct Process  *MPTask;
  47. extern struct MsgPort *CatchPort;
  48. extern struct Screen ASM *(*OldOpenScreen)(REG __a0 struct NewScreen *,
  49.                                            REG __a6 struct IntuitionBase *);
  50. extern struct Screen ASM *(*OldOpenScreenTagList)(REG __a0 struct ExtNewScreen *ns,
  51.                                                   REG __a1 struct TagItem *taglist,
  52.                                                   REG __a6 struct IntuitionBase * );
  53. extern BOOL ASM (*OldCloseScreen)   (REG __a0 struct Screen *,REG __a6 struct IntuitionBase *);
  54. extern LONG ASM (*OldCloseWorkBench)(REG __a6 struct IntuitionBase *lib);
  55.  
  56. /*********************************************************************************/
  57.  
  58. struct Screen ASM __saveds  *NewOpenScreen(REG __a0 struct ExtNewScreen *ns,
  59.                                            REG __a6 struct IntuitionBase *IBase)
  60. {
  61.   struct TagItem *taglist;
  62.   struct Screen *scr;
  63.   
  64.   InPatch++;
  65.   taglist=0;
  66.  
  67.   if(ns)
  68.   {
  69.     if(ns->Type & NS_EXTENDED)
  70.       taglist=ns->Extension;
  71.   }
  72.   
  73.   scr=NewOpenScreenTagList(ns,taglist,IBase );
  74.   InPatch--;
  75.   return(scr);
  76. }
  77.  
  78.  
  79. struct DefaultNode CenterAllNode={0};
  80.       
  81. struct Screen ASM __saveds  *NewOpenScreenTagList(REG __a0 struct ExtNewScreen *ns,
  82.                                                   REG __a1 struct TagItem *TagList,
  83.                                                   REG __a6 struct IntuitionBase *IBase)
  84. {
  85.   struct Screen *RetScreen;
  86.   struct PatchData *pd;
  87.   struct TagItem fonttags[]= { TA_DeviceDPI , (1<<16) | 1 , TAG_DONE,0 };
  88.  
  89. /**** END VARS ****/
  90.  
  91.   InPatch++;
  92.  
  93.   ObtainSemaphoreShared(&MPSem->ListSem); 
  94. //  ObtainSemaphore(&MPSem->NodeSem); 
  95.  
  96.   if(!MPSem->Enabled)
  97.   {
  98.     RetScreen=OldOpenScreenTagList(ns,TagList,IBase);
  99.     ReleaseSemaphore(&MPSem->ListSem);
  100. //    ReleaseSemaphore(&MPSem->NodeSem);
  101.     InPatch--;
  102.     return(RetScreen);
  103.   }
  104.   
  105.   if(pd=AllocVec(sizeof(struct PatchData),MEMF_CLEAR | MEMF_PUBLIC))
  106.   {
  107.     
  108.     pd->NullPens[0]=(~0);
  109.     pd->Promote=TRUE;
  110.     
  111. #ifdef ADD_DEBUG_CODE
  112.     if(MPSem->Debug)
  113.     {
  114.       KP("pd=%8lx\n",pd);
  115.       
  116.       KP("\n\n%s--------------------------------\nOpenScreenX()\n",FindTask(0)->tc_Node.ln_Name);
  117.       KP("  IntuitionBase: %8lx\n",IBase);
  118.       if(ns)
  119.       {
  120.         KP("  NewScreen    : %8lx\n",ns);
  121.         KP("    LeftEdge=%ld TopEdge=%ld\n    Width=%ld Height=%ld\n    Depth=%ld\n    dpen=%ld bpen=%ld\n    vm=%8lx type=%ld\n    font=%8lx\n",
  122.           ns->LeftEdge, ns->TopEdge, ns->Width, ns->Height, ns->Depth,
  123.           ns->DetailPen, ns->BlockPen, ns->ViewModes, ns->Type, ns->Font);
  124.         if(ns->DefaultTitle)
  125.           KP("    defaulttitle=%s\n", ns->DefaultTitle);
  126.         KP("    gadgets=%8lx  bitmap=%8lx\n",
  127.           ns->Gadgets, ns->CustomBitMap);
  128.         if(ns->Type & NS_EXTENDED)
  129.           KP("    * is NS_EXTENDED\n");
  130.       }  
  131.       if(TagList)
  132.       {
  133.         KP("  TagList:\n");
  134.         PrintTags(TagList);
  135.       }
  136.     }
  137. #endif
  138.     
  139.     /* Now that we've got the semaphore all globals are mine */
  140.     /* initialize everything */
  141.  
  142.     /* 0'ed by MEMF_CLEAR
  143.     pd->DNode=NULL;  
  144.     pd->EHB_HAM=0;
  145.     pd->TagNumber=0;
  146.     pd->ScrTitle=NULL;
  147.     pd->OpenNode=NULL;
  148.     pd->HasCustomBM=pd->Changed=pd->ModeChanged=pd->SetLook3D=pd->OverscanType=pd->Interleave=0L;
  149.  
  150.     pd->SetDepth=FALSE;
  151.     pd->IsWorkbench=0;  
  152.     */
  153.     pd->Depth=1;
  154.     pd->Width=pd->Height=pd->AutoScroll=pd->ModeID=-1;
  155.     pd->ScreenPens=pd->NullPens;
  156.     pd->TaskName=FindTask(0)->tc_Node.ln_Name;
  157.   
  158.     if(GetProgramName(pd->CLI_Name,40)) /* Get cli program's name */
  159.       if(pd->CLI_Name[0]!=0)            /* make sure pd->CLI_Name contains something */
  160.         pd->TaskName=pd->CLI_Name;
  161.     
  162.     /* Initialization Done */
  163.   
  164.     /**** Extract screen info from ns and TagList ****/  
  165.     if(ns)                     
  166.     {
  167.       pd->StoredFont  =ns->Font;
  168.       pd->Width       =ns->Width;
  169.       pd->Height      =ns->Height;
  170.       pd->ModeID      =ns->ViewModes;
  171.       pd->Depth       =ns->Depth;
  172.       pd->ScrTitle    =ns->DefaultTitle;
  173.       pd->HasCustomBM =ns->Type & CUSTOMBITMAP;
  174.       pd->IsWorkbench =(ns->Type & SCREENTYPE)==WBENCHSCREEN;
  175.     }
  176.   
  177.     if(TagList)
  178.     {
  179.       pd->HasCustomBM          =GetTagData(SA_BitMap,    pd->HasCustomBM,       TagList);
  180.       pd->Width                =GetTagData(SA_Width,     pd->Width,             TagList);
  181.       pd->Height               =GetTagData(SA_Height,    pd->Height,            TagList);
  182.       pd->AutoScroll           =GetTagData(SA_AutoScroll,pd->AutoScroll,        TagList);
  183.       pd->OverscanType         =GetTagData(SA_Overscan,  pd->OverscanType,      TagList);
  184.       pd->ModeID               =GetTagData(SA_DisplayID, pd->ModeID,            TagList);
  185.       pd->Depth                =GetTagData(SA_Depth,     pd->Depth,             TagList);
  186.       pd->ScrTitle    =(UBYTE *)GetTagData(SA_Title,    (ULONG)pd->ScrTitle,    TagList);
  187.       pd->IsWorkbench         =(GetTagData(SA_Type,      pd->IsWorkbench,       TagList) & SCREENTYPE)==WBENCHSCREEN;
  188.       pd->Interleave           =GetTagData(SA_Interleaved,pd->Interleave,       TagList);
  189.       
  190.       if(pd->Tag=FindTagItem(SA_Overscan,TagList))
  191.         if(!FindTagItem(SA_DClip,TagList))
  192.           pd->OverscanType=pd->Tag->ti_Data;
  193.       
  194.       if(pd->Tag=FindTagItem(SA_Pens,TagList))
  195.       {
  196.         pd->ScreenPens=(UWORD *)(pd->Tag->ti_Data);
  197.       }
  198.     }
  199.   
  200. #ifdef ADD_DEBUG_CODE
  201.     if(MPSem->Debug)
  202.     {
  203.       if(pd->IsWorkbench)
  204.         KP("** This is the Workbench screen, special restrictions apply **\n");
  205.     }
  206. #endif
  207.   
  208.     if(GetDisplayInfoData(0,(UBYTE *)&pd->DispInfo,sizeof(pd->DispInfo),DTAG_DISP,pd->ModeID))
  209.     {
  210.       pd->EHB_HAM=pd->DispInfo.PropertyFlags & (DIPF_IS_DUALPF | DIPF_IS_HAM | 
  211.                                        DIPF_IS_PF2PRI | DIPF_IS_EXTRAHALFBRITE);
  212.     }
  213.  
  214.     if(!pd->ScrTitle)
  215.     {
  216.       pd->ScrTitle=GetString(MSG_ITEM_NO_NAME); /* Just in case ther isn't a pd->ScrTitle */
  217.     }
  218.  
  219.     ObtainSemaphore(&MPSem->NodeSem);    
  220.  
  221.     if(pd->DNode=(struct DefaultNode *)GetTagData(SA_ModeProNode, (ULONG)MatchDNode(pd->TaskName, pd->ScrTitle, pd->ModeID) ,TagList))
  222.     {
  223.       pd->DNode=DupDNode(pd->DNode); // Duplicate the node so we can release the node semaphore 
  224.     }
  225.     
  226.     ReleaseSemaphore(&MPSem->NodeSem);    
  227.  
  228. /*  
  229.     if(pd->DNode=(struct DefaultNode *)GetTagData(SA_ModeProNode, (ULONG)MatchDNode(pd->TaskName, pd->ScrTitle, pd->ModeID) ,TagList))
  230.     {
  231.       pd->DNode=DupDNode(pd->DNode); // Duplicate the node so we can release the node semaphore 
  232.       ReleaseSemaphore(&MPSem->NodeSem);    
  233.     }
  234.     else
  235. */
  236.     if(!pd->DNode)
  237.     {
  238. //      ReleaseSemaphore(&MPSem->NodeSem);     /*********************************/
  239.       
  240.       if(!pd->IsWorkbench)
  241.       {
  242.         UBYTE *modename;
  243.         STRPTR dname="";
  244.         
  245.         if(MPSem->CatchScreens && MPSem->Enabled)
  246.         {
  247.           if(modename=GetModeName(pd->ModeID));
  248.           {
  249.             //if(EZReq(0,0,ModePro,GetString(MSG_NEW_SCREEN_1),GetString(MSG_NEW_SCREEN_1_BUTTONS),pd->ScrTitle,pd->TaskName,(ULONG)modename))
  250.             {
  251.               ULONG listnum=1,button;
  252.             
  253.               if(button=EZReq(0,0,ModePro,GetString(MSG_NEW_SCREEN_2),GetString(MSG_NEW_SCREEN_2_BUTTONS),(ULONG)pd->ScrTitle,(ULONG)pd->TaskName,(ULONG)modename))
  254.               {
  255.                 switch(button)
  256.                 {
  257.                   case 1:
  258.                     dname=pd->ScrTitle;
  259.                     listnum=1;
  260.                     break;
  261.                   case 2:
  262.                     dname=pd->TaskName;
  263.                     listnum=0;
  264.                     break;
  265.                   case 3:
  266.                     dname=modename;
  267.                     listnum=2;
  268.                     break;
  269.                 }
  270.                 
  271.                 if(pd->DNode=AllocDefaultNode(dname))
  272.                 {
  273.                   LONG l;
  274.                   
  275.                   pd->DNode->Type         =listnum;
  276.                   pd->DNode->Width        =pd->Width;
  277.                   pd->DNode->Height       =pd->Height;
  278.                   pd->DNode->AutoScroll   =pd->AutoScroll;
  279.                   pd->DNode->ModeSelect   =0;
  280.                   pd->DNode->ModeID       =pd->DNode->OrigDisplayID   =pd->ModeID;
  281.                   pd->DNode->OverscanType =pd->OverscanType;
  282.                   pd->DNode->Look3D       =pd->SetLook3D;
  283.                   pd->DNode->Flags        =0;//DNF_NODELETE;  /* So MPP can't delete me */
  284.                   pd->DNode->Depth        =pd->Depth;
  285.                   
  286.                   for(l=0;l<DRIPENS && pd->ScreenPens[l]!=(~0);l++)
  287.                     pd->DNode->Pens[l]=pd->ScreenPens[l];
  288.                   
  289.                   pd->DNode=ForceEdit(pd->DNode);
  290.                 }
  291.               }
  292.             }
  293.             FreeVec(modename);
  294.           }
  295.         }
  296.       }
  297.     }
  298.  
  299.     if(!pd->DNode && MPSem->CenterAll)
  300.     {
  301.       //pd->DNode=&CenterAllNode;
  302.       CenterAllNode.CenterFlags=MPSem->CenterAll;
  303.       pd->DNode=DupDNode(&CenterAllNode);
  304.     } 
  305.   
  306.     if(pd->DNode)
  307.     {
  308.       if(pd->DNode->Flags & DNF_NEVER_PROMOTE)
  309.       {
  310.         FreeDNode(pd->DNode);
  311.         pd->DNode=0;
  312.       }
  313.       else
  314.       if(!(pd->OpenNode=AllocVec(sizeof(struct OpenNode),MEMF_CLEAR|MEMF_PUBLIC)))
  315.       {
  316.         FreeDNode(pd->DNode);
  317.         pd->DNode=0;
  318.       }
  319.     }
  320.       
  321. #ifdef ADD_DEBUG_CODE
  322.     if(MPSem->Debug)
  323.     {
  324.       if(pd->DNode)
  325.         PrintDefNode(pd->DNode);
  326.     }
  327. #endif
  328.     
  329.     if(!pd->DNode)
  330.     {
  331.       RetScreen=OldOpenScreenTagList(ns,TagList,IBase);
  332.       FreeVec(pd);
  333.       ReleaseSemaphore(&MPSem->ListSem);
  334.       InPatch--;
  335.       return(RetScreen);
  336.     }
  337.   
  338.     if(!pd->IsWorkbench)
  339.     {
  340.       switch(pd->DNode->ModeSelect)
  341.       {
  342.         case 0:
  343.           break;
  344.         case 1:
  345. #ifdef ADD_DEBUG_CODE
  346.         if(MPSem->Debug)
  347.         {
  348.           Delay(50*2);
  349.           KP("Promoting Monitor\n");
  350.         }
  351. #endif  
  352.           if(pd->ModeID > -1)
  353.           {
  354.             if(V39)
  355.             {
  356.               pd->ModeID=BestModeID(BIDTAG_SourceID       ,pd->ModeID,
  357.                                 BIDTAG_MonitorID      ,pd->DNode->ModeID & MONITOR_ID_MASK,
  358.                                 BIDTAG_Depth          ,pd->Depth,
  359.                                 BIDTAG_DIPFMustHave   ,pd->EHB_HAM,
  360.                                 TAG_SKIP              ,(pd->Width==-1 ? 1:0),
  361.                                 BIDTAG_DesiredWidth   ,pd->Width,
  362.                                 TAG_SKIP              ,(pd->Height==-1 ? 1:0),
  363.                                 BIDTAG_DesiredHeight  ,pd->Height,
  364.                                 TAG_DONE);
  365.             }
  366.             else
  367.             {
  368.               pd->ModeID= (pd->DNode->ModeID & MONITOR_ID_MASK) | (pd->ModeID & (~MONITOR_ID_MASK));
  369.             }
  370.             if(pd->ModeID==INVALID_ID) 
  371.                pd->ModeID=pd->DNode->ModeID;
  372.                 
  373.             pd->ModeChanged=TRUE;
  374.           }
  375.           break;
  376.         case 2:
  377. #ifdef ADD_DEBUG_CODE
  378.         if(MPSem->Debug)
  379.         {
  380.           Delay(50*2);
  381.           KP("Promoting ScreenMode\n");
  382.         }
  383. #endif  
  384.           pd->ModeID        =pd->DNode->ModeID/* | pd->EHB_HAM*/;
  385.           pd->OverscanType  =pd->DNode->OverscanType;
  386.           pd->Width         =pd->DNode->Width;
  387.           pd->Height        =pd->DNode->Height;
  388.       
  389.           if(pd->DNode->Flags & DEPTH)
  390.           {
  391.             pd->Depth=pd->DNode->Depth;
  392.             pd->SetDepth=TRUE;
  393.           }
  394.           pd->Changed=TRUE;
  395.           break;
  396.         case 3:
  397. #ifdef ADD_DEBUG_CODE
  398.         if(MPSem->Debug)
  399.         {
  400.           Delay(50*2);
  401.           KP("Promoting with Requester\n");
  402.         }
  403. #endif  
  404.           if((pd->SReq=(struct ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest,
  405.                       ASLSM_TitleText             ,pd->ScrTitle,
  406.                       ASLSM_DoWidth               ,TRUE ,
  407.                       ASLSM_DoHeight              ,TRUE ,
  408.                       ASLSM_DoOverscanType        ,TRUE ,
  409.                       ASLSM_DoAutoScroll          ,TRUE ,
  410.                       ASLSM_DoDepth               ,pd->DNode->Flags & DEPTH,
  411.                       ASLSM_InitialAutoScroll     ,pd->DNode->AutoScroll,
  412.                       ASLSM_InitialDisplayWidth   ,pd->DNode->Width,
  413.                       ASLSM_InitialDisplayHeight  ,pd->DNode->Height,
  414.                       ASLSM_InitialDisplayID      ,pd->DNode->ModeID,
  415.                       ASLSM_InitialDisplayDepth   ,pd->DNode->Depth,
  416.                       ASLSM_NegativeText          ,GetString(MSG_REQ_USE_DEFAULT),
  417.                       ASLSM_PropertyFlags         ,0,
  418.                       ASLSM_PropertyMask          ,BADMODES,                      
  419.                       TAG_END 
  420.                       )))
  421.           {
  422.             if(AslRequest(pd->SReq,NULL))
  423.             {
  424.               pd->ModeID        =pd->SReq->sm_DisplayID /* | pd->EHB_HAM */; // Can't OR display ID's to get HAM or EHB!
  425.               pd->OverscanType  =pd->SReq->sm_OverscanType;
  426.               pd->Width         =pd->SReq->sm_DisplayWidth;
  427.               pd->Height        =pd->SReq->sm_DisplayHeight;    
  428.               pd->Changed       =TRUE;
  429.               if(pd->DNode->Flags & DEPTH)
  430.               {
  431.                 pd->Depth=pd->SReq->sm_DisplayDepth;
  432.                 pd->SetDepth=TRUE;
  433.               }
  434.             }
  435.             else
  436.             {
  437.               pd->Promote=FALSE;
  438.             }
  439.             FreeAslRequest(pd->SReq);  
  440.           }
  441.           break; 
  442.       }/* end switch*/
  443.       
  444. #ifdef ADD_DEBUG_CODE
  445. //      KP("end switch\n");
  446.       //Delay(50*1);
  447. #endif  
  448.   
  449.       /**** Setup promoted taglist ****/
  450.       if(pd->Promote)
  451.       {
  452.         pd->SetLook3D   = pd->DNode->Look3D;
  453.         pd->Interleave  =(pd->DNode->Flags & INTERLEAVE) | pd->Interleave;
  454.         pd->ScreenPens  = pd->DNode->Pens;
  455.         pd->AutoScroll  = pd->DNode->AutoScroll;
  456.         pd->BlankBorder = pd->DNode->Flags & DNF_BLANK_BORDER;
  457.         pd->Behind      = pd->DNode->Flags & DNF_BEHIND;
  458.                  
  459.         if( (pd->DNode->Flags & DNF_FORCEPLANAR)        && 
  460.             (pd->Width>0)                               && 
  461.             (pd->Height>0)                              &&
  462.             (!pd->HasCustomBM)                          &&
  463.             (V39)                                       &&
  464.             (pd->Depth>0)  )
  465.         {
  466.     
  467.           if(pd->BitMap=AllocBitMap(pd->Width,pd->Height,pd->Depth,BMF_CLEAR|BMF_DISPLAYABLE,0))
  468.           {
  469.             {
  470.               pd->OpenNode->Flags|=ON_BITMAP;
  471.             
  472.               pd->OpenNode->BitMap=pd->BitMap;
  473.               pd->NewTags[pd->TagNumber].ti_Tag=SA_BitMap;
  474.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->BitMap;
  475.               pd->TagNumber++;
  476.             }
  477.           }
  478.         }
  479.         
  480.       
  481.         if(pd->Changed && !(pd->HasCustomBM))
  482.         {
  483.           if(pd->Width!=0)
  484.           {
  485.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Width;
  486.             pd->NewTags[pd->TagNumber].ti_Data=pd->Width;
  487.             pd->TagNumber++;
  488.           }
  489.           if(pd->Height!=0)
  490.           {
  491.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Height;
  492.             pd->NewTags[pd->TagNumber].ti_Data=pd->Height;
  493.             pd->TagNumber++;
  494.           }
  495.           
  496.           if(FindTagItem(SA_DClip,TagList))
  497.           { // if it specifies a dclip, i need to override it.
  498.             if(QueryOverscan(pd->ModeID,&pd->ODClip,pd->OverscanType))
  499.             {
  500.               pd->NewTags[pd->TagNumber].ti_Tag=SA_DClip;
  501.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)&pd->ODClip;
  502.               pd->TagNumber++;
  503.             }
  504.           }
  505.           else
  506.           {
  507.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Overscan;
  508.             pd->NewTags[pd->TagNumber].ti_Data=pd->OverscanType;
  509.             pd->TagNumber++;
  510.           }
  511.         }
  512.       
  513.         if(pd->ModeChanged || pd->Changed)
  514.         {
  515.           pd->NewTags[pd->TagNumber].ti_Tag=SA_DisplayID;
  516.           pd->NewTags[pd->TagNumber].ti_Data=pd->ModeID;
  517.           pd->TagNumber++;
  518.         }
  519.     
  520.         if(pd->DNode->Flags & SHAREPENS)
  521.         {
  522.           pd->NewTags[pd->TagNumber].ti_Tag=SA_SharePens;
  523.           pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  524.           pd->TagNumber++;
  525.         }
  526.     
  527.         if(pd->SetDepth && !(pd->HasCustomBM) && !(pd->EHB_HAM))
  528.         {
  529.           pd->NewTags[pd->TagNumber].ti_Tag=SA_Depth;
  530.           pd->NewTags[pd->TagNumber].ti_Data=pd->Depth;
  531.           pd->TagNumber++;
  532.     
  533.         }
  534.     
  535.         
  536.         if((pd->DNode->Flags & DNF_PALETTE) && pd->DNode->Palette && pd->DNode->Colors)
  537.         {
  538.           if(V39)
  539.           {    
  540.             pd->Colors32[0]=pd->DNode->Colors<<16;
  541.             CopyMemQuick(pd->DNode->Palette,&pd->Colors32[1],pd->DNode->Colors*3*sizeof(ULONG));
  542.             pd->Colors32[pd->DNode->Colors*3+2]=0;
  543.             
  544.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Colors32;
  545.             pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->Colors32;
  546.             pd->TagNumber++;
  547.           }
  548.           else
  549.           {
  550.             ULONG c;
  551.       
  552.             for(c=0;c<pd->DNode->Colors;c++)
  553.             {
  554.               pd->ColorSpec[c].ColorIndex=c;
  555.               pd->ColorSpec[c].Red   =pd->DNode->Palette[c].Red>>28;
  556.               pd->ColorSpec[c].Green =pd->DNode->Palette[c].Green>>28;
  557.               pd->ColorSpec[c].Blue  =pd->DNode->Palette[c].Blue>>28;
  558.             }
  559.             pd->ColorSpec[c].ColorIndex=-1;
  560.             
  561.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Colors; 
  562.             pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->ColorSpec;
  563.             pd->TagNumber++;
  564.           }
  565.         }
  566.     
  567.         switch(pd->DNode->FontType)
  568.         {
  569.           case SFONT_SYS:
  570.             if(ns) ns->Font=0;
  571.             pd->NewTags[pd->TagNumber].ti_Tag=SA_SysFont;
  572.             pd->NewTags[pd->TagNumber].ti_Data=1;
  573.             pd->TagNumber++;
  574.             break;
  575.           case SFONT_MP:
  576.             if(pd->DNode->Font.tta_Name)
  577.             {
  578. //              if(pd->OpenNode=AllocOpenNode(pd->OpenNode))
  579.               {
  580.                 pd->OpenNode->Flags|=ON_FONT;
  581.               
  582.                 pd->NewTags[pd->TagNumber].ti_Tag  =SA_Font;
  583.                 pd->NewTags[pd->TagNumber].ti_Data =(ULONG)&pd->OpenNode->TA;
  584.                 pd->TagNumber++;
  585.       
  586.                 if(pd->DNode->Flags & FIXASPECT && pd->ModeID != -1)
  587.                 {
  588.                   if(GetDisplayInfoData(NULL,(UBYTE *)&pd->DispInfo,sizeof(struct DisplayInfo),DTAG_DISP,pd->ModeID))
  589.                   {
  590.                     fonttags[0].ti_Data=(ULONG)pd->DispInfo.Resolution.x|(((ULONG)pd->DispInfo.Resolution.y)<<16);
  591.                     pd->DNode->Font.tta_Style |= FSF_TAGGED;
  592.                     pd->DNode->Font.tta_Tags   =fonttags;
  593.                   }
  594.                 }
  595.                 CloneTextAttr(&pd->DNode->Font,&pd->OpenNode->TA);
  596.       
  597.                 pd->DNode->Font.tta_Style &= (~FSF_TAGGED);
  598.                 pd->DNode->Font.tta_Tags=NULL;
  599.               }
  600.             }
  601.             break;
  602.         }
  603.     
  604.         if(pd->DNode->PubOptions==1 && pd->DNode->PubName)
  605.         {
  606.           ULONG error=FALSE;
  607.           struct TagItem badtags[]=
  608.           {
  609.             SA_BitMap,    1<<0,
  610. //          SA_PubName,   1<<1,
  611.             SA_PubSig,    1<<2,
  612.             SA_PubTask,   1<<3,
  613.             SA_BackFill,  1<<4,
  614.             TAG_DONE,     0
  615.           };
  616.           
  617.           if(TagList) error =PackBoolTags(0,TagList,badtags);
  618.           if(ns)      error|=(ns->Type & CUSTOMBITMAP);
  619.           
  620.           if(error==0)
  621.           {
  622. //            if(pd->OpenNode=AllocOpenNode(pd->OpenNode))
  623.             {
  624.               struct OpenNode *won;
  625.               UBYTE number[8];
  626.               ULONG cnt=1,len;
  627.               
  628.               strncpy(pd->OpenNode->PubName,pd->DNode->PubName,MAXPUBSCREENNAME);
  629.               pd->OpenNode->PubName[MAXPUBSCREENNAME]=0;
  630.               len=strlen(pd->OpenNode->PubName);
  631.               len=min(len,MAXPUBSCREENNAME-9);
  632.               
  633.               ObtainSemaphore(&MPSem->OpenListSem);
  634.               
  635.               won=(struct OpenNode *)MPSem->OpenList.lh_Head;
  636.               while(won->on_Node.ln_Succ)
  637.               {
  638.                 if(cnt > 1)   
  639.                 {
  640.                   number[0]='.';
  641.                   stci_d(&number[1],cnt);        
  642.                   pd->OpenNode->PubName[len]=0;
  643.                   strncat(pd->OpenNode->PubName,number,MAXPUBSCREENNAME);
  644.                   pd->OpenNode->PubName[MAXPUBSCREENNAME]=0;
  645.                 }
  646.                 
  647.                 if(0==strcmp(pd->OpenNode->PubName,won->PubName))
  648.                 {
  649.                   won=(struct OpenNode *)MPSem->OpenList.lh_Head;
  650.                   cnt++;
  651.                 }
  652.                 else
  653.                   won=(struct OpenNode *)won->on_Node.ln_Succ;
  654.               }
  655.               
  656.               ReleaseSemaphore(&MPSem->OpenListSem);
  657.               
  658.               pd->OpenNode->ScreenTitle=CopyString(pd->ScrTitle,MEMF_PUBLIC); 
  659.               // Name cloned, when app CloseScreen's this title replaces the app supplied one
  660.               
  661.               pd->OpenNode->PubName[MAXPUBSCREENNAME]=0;
  662.               pd->OpenNode->Flags|= ON_PUBLIC | ON_OPEN;
  663.               
  664.               /*
  665.               pd->NewTags[pd->TagNumber].ti_Tag=SA_Title;
  666.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->OpenNode->ScreenTitle;
  667.               pd->TagNumber++;
  668.               */
  669.       
  670.               pd->NewTags[pd->TagNumber].ti_Tag=SA_PubName;
  671.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->OpenNode->PubName;
  672.               pd->TagNumber++;
  673.           
  674.               pd->NewTags[pd->TagNumber].ti_Tag=SA_PubSig;
  675.               pd->NewTags[pd->TagNumber].ti_Data=PublicSignal;
  676.               pd->TagNumber++;
  677.               
  678.               pd->NewTags[pd->TagNumber].ti_Tag=SA_PubTask;
  679.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)MPTask;
  680.               pd->TagNumber++;
  681.               
  682.               
  683.               if(!(pd->OpenNode->Flags & ON_FONT))
  684.               {
  685.                 struct TTextAttr *ot=NULL;
  686.                 
  687.                 if(ns)  ot=(struct TTextAttr *)ns->Font;          
  688.                 ot=(struct TTextAttr *)GetTagData(SA_Font,(ULONG)ot,TagList);
  689.                 
  690.                 if(ot)
  691.                 {
  692.                   pd->OpenNode->Flags|=ON_FONT;
  693.       
  694.                   CloneTextAttr(ot,&pd->OpenNode->TA);
  695.       
  696.                   pd->NewTags[pd->TagNumber].ti_Tag =SA_Font;
  697.                   pd->NewTags[pd->TagNumber].ti_Data=(ULONG)&pd->OpenNode->TA;
  698.                   pd->TagNumber++;
  699.                 }
  700.               }
  701.             }
  702.           }
  703.         }
  704.       } /* end - if(pd->Promote) */
  705.     }/* end - if(!pd->IsWorkbench) */
  706.     else  
  707.     { /* Yes, this is the Workbench screen */
  708. //      if(pd->OpenNode=AllocOpenNode(pd->OpenNode))
  709.         pd->OpenNode->Flags|=ON_WORKBENCH;
  710.     }
  711.   
  712.     if(pd->Promote)
  713.     {
  714.       if(pd->SetLook3D)
  715.       {
  716.         LONG dp;
  717.         
  718.         if(pd->DNode->Flags & DNF_3D_DEFAULT)
  719.         {
  720.           if(V39 && pd->Depth>1 && MPSem->PPrefsSet)
  721.           {
  722.             /* Use 4 color palette from prefs */
  723.             for(dp=0;dp<DRIPENS;dp++)
  724.               pd->DriPens[dp]=MPSem->PPrefs.pap_4ColorPens[dp] & 0xff;
  725.             pd->DriPens[dp]=~0;
  726.           }
  727.           else
  728.             pd->DriPens[0]=~0;
  729.         }
  730.         else
  731.         {
  732.           for(dp=0;dp<DRIPENS;dp++)
  733.             pd->DriPens[dp]=pd->DNode->Pens[dp] & 0xff;
  734.           pd->DriPens[dp]=~0;
  735.         }
  736.         
  737.         pd->NewTags[pd->TagNumber].ti_Tag=SA_Pens;
  738.         pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->DriPens;
  739.         pd->TagNumber++;
  740.         /*
  741.         if(pd->Depth==1)
  742.         {
  743.           pd->Depth=2;  // This nolonger works
  744.           pd->SetDepth=TRUE;
  745.           //  pd->NewTags[pd->TagNumber].ti_Tag=SA_Depth;
  746.           //  pd->NewTags[pd->TagNumber].ti_Data=2;
  747.           //   pd->TagNumber++;
  748.         }*/
  749.       }
  750.     
  751.       if(pd->AutoScroll)
  752.       {
  753.         pd->NewTags[pd->TagNumber].ti_Tag=SA_AutoScroll;
  754.         pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  755.         pd->TagNumber++;
  756.       }
  757.  
  758.       if(pd->Behind)
  759.       {
  760.         pd->NewTags[pd->TagNumber].ti_Tag=SA_Behind;
  761.         pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  762.         pd->TagNumber++;
  763.       }    
  764.       
  765.       if(pd->DNode->CenterFlags)
  766.       {    
  767.         if(QueryOverscan(pd->ModeID,&pd->ODClip,pd->OverscanType))
  768.         //if(GetDisplayInfoData(NULL,(UBYTE *)&pd->DimInfo,sizeof(struct DimensionInfo),DTAG_DIMS,pd->ModeID))
  769.         {
  770.           if(pd->DNode->CenterFlags & 1)
  771.           {
  772.             if(pd->Width>-1 && pd->ODClip.MaxX > pd->ODClip.MinX)
  773.             {
  774. #ifdef ADD_DEBUG_CODE
  775.               if(MPSem->Debug)
  776.               {
  777.                 KP("  ODClip.MinX=%ld  ODClip.MaxX=%ld  Width=%ld\n",pd->ODClip.MinX,pd->ODClip.MaxX,pd->Width);
  778.               }
  779. #endif
  780.  
  781.               pd->NewTags[pd->TagNumber].ti_Tag=SA_Left;
  782.               pd->NewTags[pd->TagNumber].ti_Data=((pd->ODClip.MaxX-pd->ODClip.MinX)-pd->Width)/2+pd->ODClip.MinX;
  783.               pd->TagNumber++;
  784.             }
  785.           }
  786.           if(pd->DNode->CenterFlags & 2)
  787.           {
  788.             if(pd->Height>-1 && pd->ODClip.MaxX > pd->ODClip.MinX)
  789.             {
  790. #ifdef ADD_DEBUG_CODE
  791.               if(MPSem->Debug)
  792.               {
  793.                 KP("  ODClip.MinY=%ld  ODClip.MaxY=%ld  Height=%ld\n",pd->ODClip.MinY,pd->ODClip.MaxY,pd->Height);
  794.               }
  795. #endif
  796.               
  797.               pd->NewTags[pd->TagNumber].ti_Tag=SA_Top;
  798.               pd->NewTags[pd->TagNumber].ti_Data=((pd->ODClip.MaxY-pd->ODClip.MinY)-pd->Height)/2+pd->ODClip.MinY;
  799.               pd->TagNumber++;
  800.             }
  801.           }
  802.           
  803. #ifdef ADD_DEBUG_CODE         
  804.           PrintOverscanInfo(pd);
  805. #endif
  806.           
  807.         }
  808.       }
  809.        
  810.       if(pd->DNode->Flags & SCRHOTKEY && pd->DNode->HotKey)
  811.       {
  812. //        if(pd->OpenNode=AllocOpenNode(pd->OpenNode))
  813.         {
  814.           if(pd->OpenNode->HotKey=AllocVec(strlen(pd->DNode->HotKey)+1,MEMF_CLEAR|MEMF_PUBLIC))
  815.           {
  816.             strcpy(pd->OpenNode->HotKey,pd->DNode->HotKey);
  817.             pd->OpenNode->Cx=AddHotKey(Broker,BrokerPort,pd->OpenNode->HotKey,(ULONG)pd->OpenNode);
  818.           }
  819.         }
  820.       }
  821.       
  822.     
  823.       if(pd->Interleave && !(pd->HasCustomBM))
  824.       {
  825.         pd->NewTags[pd->TagNumber].ti_Tag=SA_Interleaved;
  826.         pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  827.         pd->TagNumber++;
  828.       }
  829.         
  830.       pd->NewTags[pd->TagNumber].ti_Tag=SA_MinimizeISG; /*** just a little extra for v40 ***/
  831.       pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  832.       pd->TagNumber++;
  833.     
  834.       if(TagList)
  835.       {
  836.         pd->NewTags[pd->TagNumber].ti_Tag=TAG_MORE;
  837.         pd->NewTags[pd->TagNumber].ti_Data=(ULONG)TagList;
  838.       }
  839.       else
  840.       {
  841.         pd->NewTags[pd->TagNumber].ti_Tag=TAG_DONE;
  842.         pd->NewTags[pd->TagNumber].ti_Data=0;
  843.       }
  844.       /**** End Setup TagList ****/
  845.       
  846. //      if(pd->OpenNode)
  847.       {
  848.         if(pd->OpenNode->Flags & ON_FONT)
  849.           pd->TextFont=OpenDiskFont((struct TextAttr *)&pd->OpenNode->TA);
  850.       }
  851.     } /* end - if(pd->Promote) */
  852.   
  853.   
  854. #ifdef ADD_DEBUG_CODE  
  855.     if(MPSem->Debug)
  856.     {
  857.       Delay(50*1);
  858.       KP("  %ld new tags\n",pd->TagNumber);
  859.       KP("  New TagList\n");
  860.       PrintTags(pd->NewTags);
  861.      
  862.       KP("  Opening\n");
  863.     }
  864. #endif
  865.   
  866.     RetScreen=OldOpenScreenTagList(ns,pd->NewTags,IBase);
  867.     if(ns)
  868.     {
  869.       ns->Font=pd->StoredFont;
  870.     }
  871.   
  872.     if(RetScreen)
  873.     {
  874.       pd->OpenNode->Screen=RetScreen;
  875.       
  876.       if(pd->BlankBorder)
  877.       {
  878.         ULONG vrt;
  879.         VideoControlTags(RetScreen->ViewPort.ColorMap,
  880.                           VTAG_BORDERBLANK_SET, TRUE,
  881.                           VTAG_IMMEDIATE        ,&vrt,
  882.                           TAG_DONE);
  883.         MakeScreen(RetScreen);
  884.       }
  885.       
  886.       AddBackdrop(RetScreen,pd->DNode);
  887.   
  888. #ifdef ADD_DEBUG_CODE  
  889.       if(MPSem->Debug)
  890.       {
  891.         Delay(50*1);
  892.         KP("  Screen Addr %8lx\n",RetScreen);
  893.       }
  894. #endif
  895.  
  896.       mpObtainPens(pd);
  897.       /**************/    
  898.       
  899.       if(pd->OpenNode->Flags & ON_FONT)
  900.         if(pd->TextFont)
  901.           CloseFont(pd->TextFont);
  902.       
  903.       if(pd->OpenNode->Flags & ON_PUBLIC)
  904.       {
  905.         PubScreenStatus(RetScreen,0);
  906.       }
  907.           
  908.       ObtainSemaphore(&MPSem->OpenListSem);
  909.       AddHead(&MPSem->OpenList,(struct Node *)pd->OpenNode);
  910.       ReleaseSemaphore(&MPSem->OpenListSem);
  911.     }
  912.     else
  913.     {
  914.       FreeOpenNode(pd->OpenNode);
  915.       
  916.       RetScreen=OldOpenScreenTagList((struct ExtNewScreen *)ns,TagList,IBase);
  917.     }
  918.     
  919.     FreeVec(pd);
  920.     
  921.     ReleaseSemaphore(&MPSem->ListSem);
  922.     InPatch--;
  923.     return(RetScreen);
  924.   }
  925. //  ReleaseSemaphore(&MPSem->NodeSem); 
  926.   ReleaseSemaphore(&MPSem->ListSem);
  927.   InPatch--;
  928.   return(0);
  929. }
  930.  
  931. BOOL __saveds ASM NewCloseScreen(REG __a0 struct Screen *S,
  932.                                  REG __a6 struct IntuitionBase *IBase)
  933. {
  934.   struct OpenNode *on;
  935.   BOOL rv,found=FALSE;
  936.  
  937.   InPatch++;
  938.  
  939. #ifdef ADD_DEBUG_CODE  
  940.   if(MPSem->Debug)
  941.   {
  942.     KP("--------------------------------\nCloseScreen(%8lx) -- %s\n",S,FindTask(0)->tc_Node.ln_Name);
  943.   }
  944. #endif
  945.  
  946.   ObtainSemaphore(&MPSem->OpenListSem);
  947.   
  948.   RemoveBackdrop(S);
  949.   
  950.   on=(struct OpenNode *)MPSem->OpenList.lh_Head;
  951.   while(on->on_Node.ln_Succ)
  952.   {
  953.     if(on->Screen==S)
  954.     {
  955.       Remove((struct Node *)on);
  956.       found=TRUE;
  957.       break;
  958.     }
  959.     on=(struct OpenNode *)on->on_Node.ln_Succ;
  960.   }
  961.   
  962.   if(found)
  963.   {
  964.     if(on->Flags & ON_PUBLIC)
  965.     {
  966.       on->Flags&=(~ON_OPEN);
  967.       S->DefaultTitle=S->Title=on->ScreenTitle;
  968.       ShowTitle(S,TRUE);
  969.       AddHead(&MPSem->OpenList,(struct Node *)on);
  970.       rv=TRUE;
  971.       Signal((struct Task *)MPTask,1<<PublicSignal);
  972.     }
  973.     else // Not public
  974.     {
  975.       /*
  976.       if(on)
  977.         SendOptionMsg(MP_SCREENCLOSING,0,0,on);
  978.         */
  979.       PreCloseOpenNode(on);
  980.       if(rv=OldCloseScreen(S,IBase))
  981.         FreeOpenNode(on);
  982.       else
  983.         if(on)
  984.           AddHead(&MPSem->OpenList,(struct Node *)on);  
  985.     }
  986.               
  987.   }
  988.  
  989. #ifdef ADD_DEBUG_CODE  
  990.   if(MPSem->Debug)
  991.   {
  992.     KP("  RV=%d\n",rv);
  993.   }
  994. #endif
  995.  
  996.   InPatch--;
  997.   
  998.   ReleaseSemaphore(&MPSem->OpenListSem);
  999.   
  1000.   return(rv);
  1001. }
  1002.  
  1003.  
  1004. LONG __saveds ASM NewCloseWorkBench(REG __a6 struct IntuitionBase *IBase)
  1005. {   
  1006.   LONG retval;
  1007.   
  1008. #ifdef ADD_DEBUG_CODE  
  1009.   if(MPSem->Debug)
  1010.   {
  1011.     KP("--------------------------------\nCloseWorkBench() -- %s\n",FindTask(0)->tc_Node.ln_Name);
  1012.   }
  1013. #endif
  1014.  
  1015.   //ObtainSemaphore(&MPSem->OpenListSem);
  1016.   //SendOptionMsg(MP_SCREENCLOSING,0,0,ON);
  1017.   PreCloseWBOpenNode();
  1018.   if(retval=OldCloseWorkBench(IBase))
  1019.     FreeWBOpenNode();
  1020.   
  1021.   //ReleaseSemaphore(&MPSem->OpenListSem);
  1022.  
  1023. #ifdef ADD_DEBUG_CODE  
  1024.   if(MPSem->Debug)
  1025.   {
  1026.     KP("  RV=%d\n",retval);
  1027.   }
  1028. #endif
  1029.   return(retval);
  1030. }
  1031.  
  1032. void CatchDNode(ULONG Dest, UBYTE *Name, struct DefaultNode *SrcNode)
  1033. {
  1034.   struct DefaultNode *dnode;
  1035.   LONG l;
  1036.   
  1037.   if(dnode=AllocDefaultNode(Name))
  1038.   {
  1039.     dnode->Type         =Dest;
  1040.     dnode->Width        =SrcNode->Width;
  1041.     dnode->Height       =SrcNode->Height;
  1042.     dnode->AutoScroll   =SrcNode->AutoScroll;
  1043.     dnode->ModeSelect   =0;
  1044.     dnode->ModeID       =SrcNode->ModeID;
  1045.     dnode->OverscanType =SrcNode->OverscanType;
  1046.     dnode->Look3D       =SrcNode->Look3D;
  1047.     dnode->Flags        =SrcNode->Flags;
  1048.     dnode->Depth        =SrcNode->Depth;
  1049. /******* change to <= */
  1050.     for(l=0;l<DRIPENS;l++)
  1051.       dnode->Pens[l]      =SrcNode->Pens[l];
  1052.     
  1053.     PutMsg(CatchPort,(struct Message *)dnode);
  1054.   }
  1055.   return;
  1056. }
  1057.  
  1058. /* Go into forced edit mode, user must edit this node before returning */
  1059. struct DefaultNode *ForceEdit(struct DefaultNode *DNode)
  1060. {
  1061.   struct DefaultNode *retval;
  1062.   struct MsgPort *rport;
  1063.   struct MPMessage *mpm;
  1064.  
  1065.   retval=0;
  1066.   
  1067.   if(rport=CreateMsgPort())
  1068.   {
  1069.     if(mpm=AllocVec(sizeof(struct MPMessage),MEMF_PUBLIC|MEMF_CLEAR))
  1070.     {
  1071.       mpm->mp_Message.mn_Length=sizeof(struct MPMessage);
  1072.       mpm->mp_Message.mn_ReplyPort=rport;
  1073.       
  1074.       /* send message to Daemon - SHOWGUI */
  1075.       mpm->Command=MP_SHOWGUI;
  1076.       
  1077.       PutMsg(MPSem->DaemonPort,(struct Message *)mpm);
  1078.       WaitForReply((struct Message *)mpm);
  1079.     
  1080.       if(mpm->Code)
  1081.       {
  1082.         ObtainSemaphore(&MPSem->PortSem);
  1083.         
  1084.         /* send message to ForceEditPort owner */
  1085.         mpm->Data=DNode;
  1086.         mpm->Command=MP_FORCEDEDIT;
  1087.  
  1088.         
  1089.         PutMsg(&MPSem->ForcedEditPort,(struct Message *)mpm);
  1090.  
  1091.         ReleaseSemaphore(&MPSem->PortSem);
  1092.         
  1093.         WaitForReply((struct Message *)mpm);
  1094.   
  1095.   /*
  1096.         rm=0;
  1097.         while(rm!=mpm)
  1098.         {
  1099.           WaitPort(rport);
  1100.           rm=(struct MPMessage *)GetMsg(rport);
  1101.         }
  1102.     */  
  1103.         switch(mpm->Code)
  1104.         {
  1105.           case MPFE_USEDELETE:
  1106.             retval=DNode; // return DNode for use.
  1107.             break;
  1108.             
  1109.           case MPFE_NEVER:
  1110.             DNode->Flags=DNF_NEVER_PROMOTE;  // Set flag and give to MP
  1111.             PutMsg(CatchPort,(struct Message *)DNode);
  1112.             retval =0;
  1113.             break;
  1114.             
  1115.           case MPFE_SAVEUSE:
  1116.             {
  1117.               retval =DNode;
  1118.               if(DNode  =DupDNode(retval))   /* Duplicate, give copy to MP and then use orignal for promotion */
  1119.               {
  1120.                 PutMsg(CatchPort,(struct Message *)DNode);
  1121.               }
  1122.             }
  1123.             break;
  1124.             
  1125.           case MPFE_CANCEL:
  1126.           default:
  1127.             /* Delete the new node */
  1128.             FreeDNode(DNode);
  1129.         }//END SWITCH
  1130.       }
  1131.       FreeVec(mpm);
  1132.     }
  1133.     DeleteMsgPort(rport);
  1134.   }
  1135.   return(retval);
  1136. }
  1137.  
  1138. void WaitForReply(struct Message *Msg)
  1139. {
  1140.   struct Message *m;
  1141.   struct MsgPort *port;
  1142.   
  1143.   m=0;
  1144.   port=Msg->mn_ReplyPort;
  1145.   
  1146.   while(m!=Msg)
  1147.   {
  1148.     WaitPort(port);
  1149.     m=GetMsg(port);
  1150.   }
  1151. }
  1152.  
  1153.  
  1154. /*
  1155. BOOL SendOptionsMsg(ULONG Command, ULONG Code, struct DefaultNode *DN, struct OpenNode *ON)
  1156. {
  1157.   struct MsgPort *mport;
  1158.   struct MPScreenMessage mpsm;
  1159.   
  1160.   if(mport=CreateMsgPort())
  1161.   {
  1162.     mpm.mp_Message.mn_ReplyPort=mport;
  1163.     mpm.mp_Message.mn_Length=sizeof(mpsm);
  1164.     mpm.Command=Command;
  1165.     mpm.Code=Code;
  1166.     mpm.DN=DN;
  1167.     mpm.ON=ON;
  1168.  
  1169.     ObtainSemaphore(&MPSem->OptionSem);
  1170.     PutMsg(&MPSem->OptionPort,(struct Message *)mpsm);
  1171.     ReleaseSemaphore(&MPSem->OptionSem);
  1172.  
  1173.     WaitForReply((struct Message *)mpsm);
  1174.  
  1175.     DeleteMsgPort(mport);
  1176.     return(1);
  1177.   }
  1178.   return(0);
  1179. }
  1180.  
  1181. */
  1182.  
  1183.  
  1184. /*
  1185.   
  1186.       if(pd->DNode->Flags & SHAREPENS && 
  1187.          pd->DNode->LockedPens        && 
  1188.          V39)
  1189.       {
  1190.         UBYTE *str,state=0,done=FALSE;
  1191.         WORD num=0,num1=0,num2;
  1192.         struct ColorMap *cm;
  1193.         
  1194.         cm=RetScreen->ViewPort.ColorMap;
  1195.         
  1196.         str=pd->DNode->LockedPens;
  1197.         
  1198.         while(!done)
  1199.         {
  1200.           if(!*str) done=TRUE;
  1201.           
  1202.           if(*str>='0' && *str<='9')
  1203.           {
  1204.             if(state==0)
  1205.               state=1;
  1206.             num=0;
  1207.             while(*str>='0' && *str<='9')
  1208.             {
  1209.               num*=10;
  1210.               num+=*str - '0';
  1211.               str++;
  1212.             }
  1213.             
  1214.             switch(state)
  1215.             {
  1216.               case 1:
  1217. #ifdef ADD_DEBUG_CODE  
  1218.                 if(MPSem->Debug)
  1219.                 {
  1220.                   KP("  obtaining pen %ld\n",num);
  1221.                 }
  1222. #endif        
  1223.                 if(!pd->OpenNode->ObtainedPens[num])
  1224.                 {
  1225.                   if(-1!=ObtainPen(cm,num,0,0,0, PEN_EXCLUSIVE | PEN_NO_SETCOLOR)))
  1226.                     pd->OpenNode->ObtainedPens[num]=1;
  1227.                 }
  1228.                 break;
  1229.               case 2:
  1230.                 for(num2=num1+1;num2<=num;num2++)
  1231.                 {
  1232. #ifdef ADD_DEBUG_CODE  
  1233.                   if(MPSem->Debug)
  1234.                   {
  1235.                     KP("  obtaining pen %ld\n",num2);
  1236.                   }
  1237. #endif
  1238.                   if(!pd->OpenNode->ObtainedPens[num2])
  1239.                   {
  1240.                     if(-1!=ObtainPen(cm,num2,0,0,0, PEN_EXCLUSIVE | PEN_NO_SETCOLOR))
  1241.                       pd->OpenNode->ObtainedPens[num2]=1;
  1242.                   }
  1243.                 }
  1244.                 break;
  1245.             }
  1246.             state=0;
  1247.            
  1248.           }
  1249.           
  1250.           if(*str==' ')
  1251.             for(;*str==' ';str++);
  1252.           else
  1253.             if(*str=='-')
  1254.             {
  1255.               num1=num;
  1256.               state=2;
  1257.               str++;
  1258.             }
  1259.             else
  1260.               str++;
  1261.         }
  1262.       }
  1263.       
  1264.       */
  1265.